import {combineReducers} from 'redux'
import * as actionType from '../action/actionType'
import localStorage from "../../utils/storage"

//需要存储的初始状态数据
const initialState = {
    skin: localStorage.getSkin(),  //皮肤
    showStatus: false,  //显示状态
    playIndex: 0, // 当前播放是第几首个
    song: localStorage.getCurrentSong(),  //当前歌曲
    songs: localStorage.getSongs()  //歌曲列表
}

const song = (song = initialState.song, action) => {
    switch (action.type) {
        case actionType.CHANGE_CURRENT_SONG:
            localStorage.setCurrentSong(action.song)
            localStorage.setPlayIndex(action.index)
            return action.song
        default:
            return song
    }
}

const songs = (songs = initialState.songs, action) => {
    switch (action.type) {
        case actionType.SET_SONGS:
            localStorage.setSongs(action.songs)
            return action.songs
        default:
            return songs
    }
}



const reducer = combineReducers({
    song,
    songs
})

export  default reducer